package com.example.dbdesign.pojo.vo;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;

@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Res<T> {
    private int status;

    private String msg;

    private T data;

    private Long timeStamp;

    public Res(){

    }

    public Res(int status, String msg, T data, Long timeStamp) {
        this.status = status;
        this.msg = msg;
        this.data = data;
        this.timeStamp = timeStamp;
    }

    public static <T> Res<T> success(T data) {
        return new Res<>(200, "success", data, System.currentTimeMillis());
    }

    public static <T> Res<T> fail() {
        return new Res<>(500, "fail", null,System.currentTimeMillis());
    }

    public static <T> Res<T> fail(String msg) {
        return new Res<>(500, msg, null, System.currentTimeMillis());
    }

    public static <T> Res<T> fail(int status, String msg) {
        return new Res<>(status, msg, null, System.currentTimeMillis());
    }

    public static <T> Res<T> fail(int status, String msg, T data) {
        return new Res<>(status, msg, data, System.currentTimeMillis());
    }

    public static <T> Res<T> error(int status, String msg) {
        return new Res<>(status, msg, null, System.currentTimeMillis());
    }

    public static <T> Res<T> error(String msg) {
        return new Res<>(500, msg, null, System.currentTimeMillis());
    }
}

